{% extends 'car_system/base.html' %}

{% block title %}管理后台 - 汽车数据分析系统{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h2><i class="fas fa-tachometer-alt text-primary me-2"></i> 系统管理后台</h2>
    <a href="{% url 'admin:index' %}" class="btn btn-outline-primary" target="_blank">
        <i class="fas fa-cog me-1"></i> Django 管理站点
    </a>
</div>

<!-- 统计卡片 -->
<div class="row mb-4">
    <div class="col-md-4">
        <div class="card stats-card bg-primary-light">
            <div class="card-body">
                <div class="stats-icon text-primary">
                    <i class="fas fa-users"></i>
                </div>
                <h2 class="stats-number">{{ user_count }}</h2>
                <p class="stats-title">注册用户数</p>
            </div>
        </div>
    </div>
    <div class="col-md-4">
        <div class="card stats-card bg-primary-light">
            <div class="card-body">
                <div class="stats-icon text-primary">
                    <i class="fas fa-car"></i>
                </div>
                <h2 class="stats-number">{{ car_count }}</h2>
                <p class="stats-title">车型数量</p>
            </div>
        </div>
    </div>
    <div class="col-md-4">
        <div class="card stats-card bg-primary-light">
            <div class="card-body">
                <div class="stats-icon text-primary">
                    <i class="fas fa-trademark"></i>
                </div>
                <h2 class="stats-number">{{ brand_count }}</h2>
                <p class="stats-title">品牌数量</p>
            </div>
        </div>
    </div>
</div>

<!-- 用户管理 -->
<div class="card mb-4">
    <div class="card-header bg-primary text-white">
        <div class="d-flex justify-content-between align-items-center">
            <h5 class="mb-0"><i class="fas fa-users me-2"></i>用户管理</h5>
            <a href="{% url 'admin:auth_user_add' %}" class="btn btn-sm btn-light" target="_blank">
                <i class="fas fa-plus me-1"></i> 添加用户
            </a>
        </div>
    </div>
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-hover">
                <thead class="table-light">
                    <tr>
                        <th>ID</th>
                        <th>用户名</th>
                        <th>电子邮件</th>
                        <th>姓名</th>
                        <th>注册日期</th>
                        <th>状态</th>
                        <th>权限</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for user_obj in users %}
                    <tr>
                        <td>{{ user_obj.id }}</td>
                        <td>{{ user_obj.username }}</td>
                        <td>{{ user_obj.email }}</td>
                        <td>{{ user_obj.first_name }} {{ user_obj.last_name }}</td>
                        <td>{{ user_obj.date_joined|date:"Y-m-d H:i" }}</td>
                        <td>
                            {% if user_obj.is_active %}
                            <span class="badge bg-success">活跃</span>
                            {% else %}
                            <span class="badge bg-danger">禁用</span>
                            {% endif %}
                        </td>
                        <td>
                            {% if user_obj.is_superuser %}
                            <span class="badge bg-danger">超级管理员</span>
                            {% elif user_obj.is_staff %}
                            <span class="badge bg-warning">管理员</span>
                            {% else %}
                            <span class="badge bg-secondary">普通用户</span>
                            {% endif %}
                        </td>
                        <td>
                            <div class="btn-group">
                                <a href="{% url 'admin_user_edit' user_obj.id %}" class="btn btn-sm btn-outline-primary">
                                    <i class="fas fa-edit"></i> 编辑
                                </a>
                                {% if user_obj != request.user %}
                                <a href="{% url 'admin_user_delete' user_obj.id %}" class="btn btn-sm btn-outline-danger">
                                    <i class="fas fa-trash"></i> 删除
                                </a>
                                {% endif %}
                            </div>
                        </td>
                    </tr>
                    {% empty %}
                    <tr>
                        <td colspan="8" class="text-center">暂无用户数据</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>

<!-- 系统操作 -->
<div class="row">
    <div class="col-md-6">
        <div class="card">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0"><i class="fas fa-tools me-2"></i>系统功能</h5>
            </div>
            <div class="card-body">
                <div class="list-group">
                    <a href="{% url 'add_car' %}" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
                        <div>
                            <i class="fas fa-plus-circle me-2"></i> 添加新车型
                        </div>
                        <i class="fas fa-chevron-right"></i>
                    </a>
                    <a href="{% url 'admin:index' %}" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center" target="_blank">
                        <div>
                            <i class="fas fa-cog me-2"></i> Django 管理界面
                        </div>
                        <i class="fas fa-chevron-right"></i>
                    </a>
                    <a href="{% url 'car_charts' %}" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
                        <div>
                            <i class="fas fa-chart-pie me-2"></i> 数据图表
                        </div>
                        <i class="fas fa-chevron-right"></i>
                    </a>
                </div>
            </div>
        </div>
    </div>
    
    <div class="col-md-6">
        <div class="card">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0"><i class="fas fa-info-circle me-2"></i>系统信息</h5>
            </div>
            <div class="card-body">
                <ul class="list-group">
                    <li class="list-group-item d-flex justify-content-between align-items-center">
                        <div>
                            <i class="fas fa-code me-2"></i> 系统版本
                        </div>
                        <span class="badge bg-primary">1.0.0</span>
                    </li>
                    <li class="list-group-item d-flex justify-content-between align-items-center">
                        <div>
                            <i class="fas fa-database me-2"></i> 数据库
                        </div>
                        <span class="badge bg-success">MySQL</span>
                    </li>
                    <li class="list-group-item d-flex justify-content-between align-items-center">
                        <div>
                            <i class="fas fa-chart-line me-2"></i> 图表库
                        </div>
                        <span class="badge bg-info">ECharts</span>
                    </li>
                    <li class="list-group-item d-flex justify-content-between align-items-center">
                        <div>
                            <i class="fas fa-paint-brush me-2"></i> 前端框架
                        </div>
                        <span class="badge bg-secondary">Bootstrap 5</span>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>
{% endblock %} 